﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace ConnectToDatabase
{
    public class DeleteDB : MarshalByRefObject
    {
        private string cmdtext;
        private ConnectDB connectDB = new ConnectDB();
        private string connectionString;
        private MySqlConnection connection = null;

        public int DeleteLoaiSanPham(string MaLoaiSP)
        {
            //connectDB.setConnectionString(ref connectionString);
            cmdtext = "DELETE FROM loaisanpham WHERE MaLoaiSanPham =" + MaLoaiSP; 
            return connectDB.QueryData(cmdtext);
            //cmdtext = "INSERT INTO loaisanpham VALUES(" + "'" + MaLoaiSP + "'," + "'" + TenLoaiSP + "')";
            //connection = new MySqlConnection(connectDB.setConnectionString();
            //MySqlCommand cmd = new MySqlCommand(cmdtext, connection);
            //int i = -1;

            //try
            //{
            //    //mo ket noi
            //    connection.Open();

            //    //thuc hien cau truy van thong qua MySqlCommand
            //    i = cmd.ExecuteNonQuery();
            //    return i;
            //}
            //catch (MySqlException err)
            //{
            //    Console.WriteLine("Erron:" + err.ToString());
            //    return i;
            //}
            //finally
            //{
            //    //dong ket noi 
            //    if (connection != null)
            //    {
            //        connection.Close();
            //    }
            //}
        }

        public int DeletePhieuTra(string MaPhieuTra)
        {
            //connectDB.setConnectionString(ref connectionString);
            cmdtext = "DELETE FROM dbgiaydep.phieutrahang WHERE MaPhieuTraHang ='" + MaPhieuTra + "'";

            return connectDB.QueryData(cmdtext);
        }

        public int DeleteCTPhieuTra(string MaPhieuTra)
        {
            //connectDB.setConnectionString(ref connectionString);
            cmdtext = "DELETE FROM dbgiaydep.ct_phieutrahang WHERE MaPhieuTra ='" + MaPhieuTra + "'";

            return connectDB.QueryData(cmdtext);
        }

        public int DeleteSanPham(string _MaSanPham) {
            //connectDB.setConnectionString(ref connectionString);
            cmdtext = "DELETE FROM sanpham WHERE MaSanPham =" + _MaSanPham;
            return connectDB.QueryData(cmdtext);
            //connection = new MySqlConnection(connectionString);
            //MySqlCommand cmd = new MySqlCommand(cmdtext, connection);
            //int i = -1;

            //try{
            //    connection.Open();
            //    i = cmd.ExecuteNonQuery();
            //    return i;
            //}
            //catch (MySqlException err){
            //    Console.WriteLine("Erron:" + err.ToString());
            //    return i;
            //}
            //finally{
            //    if (connection != null){
            //        connection.Close();
            //    }
            //}
        }

        public int DeleteCT_HoaDon(string _MaHD, string _MaSanPham)
        {
            //connectDB.setConnectionString(ref connectionString);
            cmdtext = "DELETE FROM ct_hoadon WHERE MaSanPham =" + _MaSanPham + " and MaHoaDon = " + _MaHD;
            return connectDB.QueryData(cmdtext);
            //connection = new MySqlConnection(connectionString);
            //MySqlCommand cmd = new MySqlCommand(cmdtext, connection);
            //int i = -1;

            //try
            //{
            //    connection.Open();
            //    i = cmd.ExecuteNonQuery();
            //    return i;
            //}
            //catch (MySqlException err)
            //{
            //    Console.WriteLine("Erron:" + err.ToString());
            //    return i;
            //}
            //finally
            //{
            //    if (connection != null)
            //    {
            //        connection.Close();
            //    }
            //}
        }

        public int DeleteCT_PhieuNhapHang(string _MaNhapHang, string _MaNhomSP)
        {
            //connectDB.setConnectionString(ref connectionString);
            cmdtext = "DELETE FROM ct_phieunhaphang WHERE MaNhapHang =" + _MaNhapHang + " and MaNhomSanPham =" + _MaNhomSP;
            return connectDB.QueryData(cmdtext);
            //connection = new MySqlConnection(connectionString);
            //MySqlCommand cmd = new MySqlCommand(cmdtext, connection);
            //int i = -1;

            //try
            //{
            //    connection.Open();
            //    i = cmd.ExecuteNonQuery();
            //    return i;
            //}
            //catch (MySqlException err)
            //{
            //    Console.WriteLine("Erron:" + err.ToString());
            //    return i;
            //}
            //finally
            //{
            //    if (connection != null)
            //    {
            //        connection.Close();
            //    }
            //}
        }

        public int DeleteCT_PhieuTraHang(string _MaPhieuTra, string _MaSanPham)
        {
            //connectDB.setConnectionString(ref connectionString);
            cmdtext = "DELETE FROM ct_phieutrahang WHERE MaPhieuTra =" + _MaPhieuTra + " and MaSanPham =" + _MaSanPham;
            return connectDB.QueryData(cmdtext);
            //connection = new MySqlConnection(connectionString);
            //MySqlCommand cmd = new MySqlCommand(cmdtext, connection);
            //int i = -1;

            //try
            //{
            //    connection.Open();
            //    i = cmd.ExecuteNonQuery();
            //    return i;
            //}
            //catch (MySqlException err)
            //{
            //    Console.WriteLine("Erron:" + err.ToString());
            //    return i;
            //}
            //finally
            //{
            //    if (connection != null)
            //    {
            //        connection.Close();
            //    }
            //}
        }

        public int DeleteDangNhap(string _MaDangNhap)
        {
            //connectDB.setConnectionString(ref connectionString);
            cmdtext = "DELETE FROM dangnhap WHERE MaDangNhap =" + _MaDangNhap;
            return connectDB.QueryData(cmdtext);
            //connection = new MySqlConnection(connectionString);
            //MySqlCommand cmd = new MySqlCommand(cmdtext, connection);
            //int i = -1;

            //try
            //{
            //    connection.Open();
            //    i = cmd.ExecuteNonQuery();
            //    return i;
            //}
            //catch (MySqlException err)
            //{
            //    Console.WriteLine("Erron:" + err.ToString());
            //    return i;
            //}
            //finally
            //{
            //    if (connection != null)
            //    {
            //        connection.Close();
            //    }
            //}
        }

        public int Test() { return 0; }
    }
}
